package com.yupi.springbootinit.bimq;


import com.yupi.springbootinit.constant.MqConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class BiProducer {

    @Resource
    RabbitTemplate rabbitTemplate;

    public void sendMessage(String message){
        rabbitTemplate.convertAndSend(MqConstant.EXCHANGE_NAME, MqConstant.ROUTING_KEY, message);
    }

    /**
     * 发送消息，保证 redis 和 mysql 双写一致性
     * */
    public void sendRedisMySQLConsistMessage(String message){
        rabbitTemplate.convertAndSend(MqConstant.EXCHANGE_NAME, MqConstant.REDIS_MYSQL_CONSIST_ROUTING_KEY, message);
    }
}
